package com.junlaninfo.service;

import com.junlaninfo.Manage.LoginManag;
import com.junlaninfo.entity.UserEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ExecutionException;

/**
 * Created by 辉 on 2020/7/24.
 * 使用异步注解async
 */
@RestController
public class LoginService3 {
    private static final Logger log = LoggerFactory.getLogger(LoginService3.class);
    @Autowired
    LoginManag  loginManag;

    @GetMapping("/login3")
    public String login(UserEntity userEntity) throws ExecutionException, InterruptedException {
        //1、先查询登录是否成功
        UserEntity userEntity1 = dbLogin(userEntity);
        if (userEntity1==null){
            return "登录名或者密码不对";
        }
        loginManag.asynLogin(userEntity);
        return  "登录成功";
    }
    private UserEntity dbLogin(UserEntity userEntity) {
        log.info(">>>1.正在查询数据库登陆<<<");
        try {
            Thread.sleep(2000);
        } catch (Exception e) {

        }
        return userEntity;
    }


}
